﻿using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Transactions;
using Newtonsoft.Json;
using T.FAS.Runtime.Base.Entity;
using T.ServiceComponent.DAC.Service;
using System.Reflection;
using System.Data;

namespace T.FAS.Runtime.Base.Dao
{
    public class ChartLibDao : DaoService<ChartLib>
    {
        public override string TableName => "FAS_ChartLib";
        public override string IDColumnName => "ID";
        public ChartLibDao() : base()
        {
            DBName = "TFAS";
        }
        public override List<string> ExceptColumnName => new List<string> {  };
        public override Dictionary<string, object> GetDataMapping(ChartLib data)
        {
            var datas = base.GetDataMapping(data);
            datas.Remove("ChartType");
            datas.Add("ChartType", (int)(data.ChartType));
            return datas;
        }
        public override ChartLib ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            var myCol = new Dictionary<string, PropertyInfo>(base.Columns);
            myCol.Remove("ChartType");
            var data = base.ConvertToObject(myCol, row);
            if (row["ChartType"] != DBNull.Value)
                data.ChartType = (ChartType)Enum.Parse(typeof(ChartType),
                                                    Convert.ToString(row["ChartType"]));
            return data;
        }
        /// <summary>
        /// 查询图表库
        /// </summary>
        /// <returns></returns>
        public List<ChartLib> GetChartLibs()
        {
            List<ChartLib> result = new List<ChartLib>();
            List<object> objects = base.GetObjectsByFilter("IsEnable=1");
            if (objects != null)
            {
                objects.ForEach(obj => result.Add(obj as ChartLib));
            }
            return result;
        }
    }
}
